<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body>

<table id="demo" lay-filter="myTableFilter"></table>

<script type="text/html" id="toolbar1">
    <a class="layui-btn layui-btn-xs" lay-event="test1">修改状态</a>
</script>

    <script>
        layui.use(['table','form','upload'], function() {

            var table = layui.table;
            var form = layui.form;
            var upload = layui.upload;

            //渲染 table表格
            table.render({
                elem: '#demo'
                , url: '${pageContext.request.contextPath}/user/selectPage' //数据接口
                , page: true //开启分页
                , limit: 5
                , limits: [3, 5, 10]
                , cols: [[ //表头
                      {field: 'userId', title: '编号'}
                    , {field: 'userName', title: '用户名'}
                    , {field: 'userNickname', title: '用户昵称'}
                    , {field: 'userSex', title: '性别'}
                    , {field: 'guruId', title: '关注的额上师'}
                    , {field: 'userStatus', title: '用户状态'}
                    , {field: 'userCreateDate', title: '创建的时间'}
                    , {title: '操作', toolbar: '#toolbar1'}
                ]]
            });

            //删除修改start
            table.on('tool(myTableFilter)',function (obj) {
                if(obj.event=='test1'){
                    //询问弹出框
                    layer.confirm('确定修改吗?',function(index){
                        $.ajax({
                            url:"${pageContext.request.contextPath}/user/update",
                            data:'userId='+obj.data.userId+'&userStatus='+obj.data.userStatus,
                            dataType:"json",
                            success:function(result){
                                if(result.flag){
                                    layer.msg("修改成功");
                                    table.reload('demo',{
                                        //从第几页开始
                                        page:{curr:1}
                                    })
                                }
                            }
                        })
                    })

                }
            })

        })
</script>
</body>
</html>
